package com.xxl.job.executor.service.duty;

import com.web.all.common.bean.response.Result;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.mvc.api.AppDutyApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 值班提醒
 * @author lc
 */
@JobHandler(value="PersonnelDutyTaskJobHandler")
@Component
public class PersonnelDutyTaskJobHandler extends IJobHandler {
	private static final Logger log = LoggerFactory.getLogger(PersonnelDutyTaskJobHandler.class);

	private final AppDutyApi appDutyApi;

	@Autowired
	public PersonnelDutyTaskJobHandler(AppDutyApi appDutyApi) {
		this.appDutyApi = appDutyApi;
	}

	@Override
	public ReturnT<String> execute(String param) throws Exception {
		XxlJobLogger.log("PersonnelDutyTaskJobHandler, 值班提醒.");
		log.info("SpecialPatrolTaskJobHandler, 值班提醒.");
		try{
			Result result = appDutyApi.notifyDuty();
			if(result.isSuccess()){
				XxlJobLogger.log("PersonnelDutyTaskJobHandler, 值班提醒成功.");
				log.info("PersonnelDutyTaskJobHandler, 值班提醒成功.");
				return SUCCESS;
			}
			XxlJobLogger.log("PersonnelDutyTaskJobHandler, 值班提醒失败.");
			log.error("PersonnelDutyTaskJobHandler, 值班提醒失败.原因：{}",result.getMsg());
			return FAIL;
		}catch (Exception e){
			log.error("PersonnelDutyTaskJobHandler, 值班提醒失败. 原因：{}",e.getMessage());
			return FAIL;
		}
	}

}
